package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.shop.service.DeliveryManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author LSY
 * @Date 2022/1/7 9:16
 * @Version 1.0
 **/
@RestController
@RequestMapping("/deliveryManagement")
@Api(tags = "商户配送管理接口集")
@CrossOrigin
public class DeliveryManagementController {

    DeliveryManagementService deliveryManagementService;
    @Autowired
    public DeliveryManagementController(DeliveryManagementService deliveryManagementService) {
        this.deliveryManagementService = deliveryManagementService;
    }

    @PostMapping(value = "/alterUnifiedDeliveryStatus")
    @ApiOperation(value = "通过卖家id修改卖家平台统一配送状态（开启或关闭）")
    public Map<String, Object> alterUnifiedDeliveryStatus() {
        deliveryManagementService.alterUnifiedDeliveryStatus();

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/alterMerchantDeliveryStatus")
    @ApiOperation(value = "通过卖家id修改商家配送状态（开启或关闭）")
    public Map<String, Object> alterMerchantDeliveryStatus() {
        deliveryManagementService.alterMerchantDeliveryStatus();

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/setUnifiedDeliveryCost")
    @ApiOperation(value = "通过卖家id修改卖家平台统一配送费")
    @ApiImplicitParam(name = "cost", value = "卖家平台统一配送费", required = true, dataType = "Double")
    public Map<String, Object> setUnifiedDeliveryCost(Double cost) {
        deliveryManagementService.setUnifiedDeliveryCost(cost);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/setMerchantDeliveryCost")
    @ApiOperation(value = "通过卖家id修改商家配送费")
    @ApiImplicitParam(name = "cost", value = "商家配送费", required = true, dataType = "Double")
    public Map<String, Object> setMerchantDeliveryCost(Double cost) {
        deliveryManagementService.setMerchantDeliveryCost(cost);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getMap();
    }

    @PostMapping(value = "/setMerchantDeliveryArea")
    @ApiOperation(value = "通过卖家id修改商家配送区域")
    @ApiImplicitParam(name = "region", value = "商家配送区域范围(KM)", required = true, dataType = "Integer")
    public Map<String, Object> setMerchantDeliveryArea(Integer region) {
        deliveryManagementService.setMerchantDeliveryArea(region);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");

        return jsonResult.getMap();
    }
}
